//
//  ActivityViewController.m
//  UI_元旦豆瓣电影
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "ActivityViewController.h"
#import "ActivityTableViewCell.h"
#import "ActivityModel.h"
#import "DetailViewController.h"
#import "UIImageView+WebCache.h"
@interface ActivityViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *tableView;
// 数组
@property (nonatomic, retain) NSMutableArray *arrData;
@property (nonatomic, retain) NSMutableArray *arrModel;
@end

@implementation ActivityViewController


- (void)dealloc {
    [_arrData release];
    [_arrModel release];
    [_tableView release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createNav];
    [self createTableView];
    [self DidHandle];
    
    
}

- (void)DidHandle {
    
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"activity" ofType:@"plist"];
    self.arrData = [NSMutableArray arrayWithContentsOfFile:path];
    self.arrModel = [NSMutableArray array];
    for (NSMutableDictionary *dic in _arrData) {
        ActivityModel *mod = [ActivityModel activityModel];
        [mod setValuesForKeysWithDictionary:dic];
        [_arrModel addObject:mod];
    }
//    ActivityModel *mod = _arrModel[0];
    
//    NSLog(@"%@", mod.content);
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _arrModel.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ActivityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    ActivityModel *mod = _arrModel[indexPath.row];
    cell.model = mod;
    
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 250;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    DetailViewController *DVC = [[DetailViewController alloc] init];
    ActivityModel *mod = _arrModel[indexPath.row];
    DVC.model = mod;
    [self.navigationController pushViewController:DVC animated:YES];
}

- (void)createNav {
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"活动";
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0 green:0.4 blue:0.5 alpha:1];

}

- (void)createTableView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView release];
    [_tableView registerNib:[UINib nibWithNibName:@"ActivityTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"cell"];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
